#!/usr/bin/bash

deployName=egrep 'deploy:(.+?)' scrapyd.cfg

mkdir spideradmin
# shellcheck disable=SC2164
cd spideradmin

nohup scrapyd >scrapyd.log 2>&1 &

# shellcheck disable=SC2009
scrapydPid=$( ps -ef | grep scrapyd | grep -v grep | awk '{ print $2 }')
if [ ! "$scrapydPid" ];then
  echo "[+]: scrapyd process is not exist"
  nohup scrapyd > scrapyd.log 2>&1 &
  echo "[+]: scrapyd start successful ......"
fi

# shellcheck disable=SC2154
scrapyd_deploy "$deployName" -p spiderNews

spideradmin init
sed -i 's/HOST = None/HOST = "0.0.0.0"/g' config.py
nohup spideradmin > spideradmin.log 2>&1 &
# shellcheck disable=SC2009
spiderAdminPid=$( ps -ef | grep spideradmin | grep -v grep | awk '{ print $2 }')
if [ ! "$spiderAdminPid" ];then
  echo "[+]: spiderAdmin process is not exist"
  nohup spideradmin > spideradmin.log 2>&1 &
  echo "[+]: spiderAdmin start successful"
fi

echo "[+]: spider project  start successful ......"




